import axios from '../../../../utils/axios'
Page({
    data: {
        searchList: [],
        searchVal: '',

    },
    onLoad: function (options) {
        const eventChannel = this.getOpenerEventChannel()
        // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
        eventChannel.on('sendsearchListData', (res) => {
            console.log(res);
            this.setData({
                searchList: res.data
            })
        })
    },
    onReady: function () {

    },
    onShow: function () {

    },
    onHide: function () {

    },
    onUnload: function () {

    },
    onPullDownRefresh: function () {

    },
    onReachBottom: function () {

    },
    onShareAppMessage: function () {

    },
    onPageScroll: function () {

    },
    //item(index,pagePath,text)
    onTabItemTap: function (item) {

    },
    searchValUpData(e) {
        this.setData({
            searchVal: e.detail
        })
    },
    async search() {
        let res = await axios({
            url: '/api/mall/product',
            data: {
                storeName: this.data.searchVal
            }
        })
        console.log(res);
        this.setData({
            searchList: res.data.content
        })
    },
    async navigationTo(e) {
        console.log('handle click', e);
        let detailData = e.currentTarget.dataset.detaildata;
        if (e.currentTarget.dataset.bannerurl) {
            let id = JSON.parse(e.currentTarget.dataset.bannerurl).id;
            let res = await axios({
                url: '/api/mall/product',
                data: {
                    id
                }
            })
            detailData = res.data.content[0]
        };
        wx.navigateTo({
            url: '../goods/goods',
            success: (res) => {
                // 发送数据        
                res.eventChannel.emit('sendDetailData', {
                    data: detailData
                })
            },
        });
    },
});